//
// Created by postgres on 3/28/17.
//
#include <stdlib.h>
#include <stdio.h>

void *pg_malloc(size_t size)
{
    void	   *tmp;

    /* Avoid unportable behavior of malloc(0) */
    if (size == 0)
        size = 1;
    tmp = malloc(size);
    if (!tmp)
    {
        fprintf(stderr, ("out of memory\n"));
        exit(EXIT_FAILURE);
    }
    return tmp;
}
/* aclloction memory1 */
void
*palloc(size_t size)
{
    return pg_malloc(size);
}

void *pg_calloc (size_t num, size_t size){
    void	   *tmp;

    /* Avoid unportable behavior of malloc(0) */
    if (size == 0)
        size = 1;
    if(num==0)
        num=1;
    tmp = calloc(num,size);
    if (!tmp)
    {
        fprintf(stderr, ("out of memory\n"));
        exit(EXIT_FAILURE);
    }
    return tmp;
}
/* aclloction memory1 */
void *pcalloc (size_t num, size_t size){
    return pg_calloc(num,size);
}
void pg_free(void *ptr)
{
    if (ptr != NULL)
        free(ptr);
}
/* aclloction memory1 */
void pfree(void *pointer)
{
    pg_free(pointer);
}
void *
pg_realloc(void *ptr, size_t size)
{
    void	   *tmp;

    /* Avoid unportable behavior of realloc(NULL, 0) */
    if (ptr == NULL && size == 0)
        size = 1;
    tmp = realloc(ptr, size);
    if (!tmp)
    {
        fprintf(stderr, ("out of memory\n"));
        exit(EXIT_FAILURE);
    }
    return tmp;
}
void *
repalloc(void *pointer, size_t size)
{
    return pg_realloc(pointer, size);
}
